package com.example.demo.Component;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Configuration
class Interceptor_method implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session=request.getSession(false);
        if (session!=null){
            return true;
        }else {
            return false;
        }
    }
}
@Configuration
public class Interceptor implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new Interceptor_method()).addPathPatterns("/**").
                excludePathPatterns("/css/**").
                excludePathPatterns("/img/**").
                excludePathPatterns("/js/**").
                excludePathPatterns("/register.html").
                excludePathPatterns("/login.html").
                excludePathPatterns("/user/login").
                excludePathPatterns("").
                excludePathPatterns("/user/register");
    }
}
